package com.central.scheduler.remote.command;

import com.central.scheduler.common.enums.ExecutionStatus;
import com.central.scheduler.common.utils.JSONUtils;

import java.io.Serializable;

/**
 * @author Tindy
 * @date 2021/11/1
 * @describe
 * db task final result response command
 */
public class StateEventChangeCommand implements Serializable {

    private String key;

    private ExecutionStatus sourceStatus;

    private Long sourceProcessInstanceId;

    private Long sourceTaskInstanceId;

    private Long destProcessInstanceId;

    private Long destTaskInstanceId;

    public StateEventChangeCommand() {
        super();
    }

    public StateEventChangeCommand(Long sourceProcessInstanceId, Long sourceTaskInstanceId,
                                   ExecutionStatus sourceStatus,
                                   Long destProcessInstanceId,
                                   Long destTaskInstanceId
    ) {
        this.key = String.format("%d-%d-%d-%d",
                sourceProcessInstanceId,
                sourceTaskInstanceId,
                destProcessInstanceId,
                destTaskInstanceId);

        this.sourceStatus = sourceStatus;
        this.sourceProcessInstanceId = sourceProcessInstanceId;
        this.sourceTaskInstanceId = sourceTaskInstanceId;
        this.destProcessInstanceId = destProcessInstanceId;
        this.destTaskInstanceId = destTaskInstanceId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    /**
     * package response command
     *
     * @return command
     */
    public Command convert2Command() {
        Command command = new Command();
        command.setType(CommandType.STATE_EVENT_REQUEST);
        byte[] body = JSONUtils.toJsonByteArray(this);
        command.setBody(body);
        return command;
    }

    @Override
    public String toString() {
        return "StateEventResponseCommand{"
                + "key=" + key
                + '}';
    }

    public ExecutionStatus getSourceStatus() {
        return sourceStatus;
    }

    public void setSourceStatus(ExecutionStatus sourceStatus) {
        this.sourceStatus = sourceStatus;
    }

    public Long getSourceProcessInstanceId() {
        return sourceProcessInstanceId;
    }

    public void setSourceProcessInstanceId(Long sourceProcessInstanceId) {
        this.sourceProcessInstanceId = sourceProcessInstanceId;
    }

    public Long getSourceTaskInstanceId() {
        return sourceTaskInstanceId;
    }

    public void setSourceTaskInstanceId(Long sourceTaskInstanceId) {
        this.sourceTaskInstanceId = sourceTaskInstanceId;
    }

    public Long getDestProcessInstanceId() {
        return destProcessInstanceId;
    }

    public void setDestProcessInstanceId(Long destProcessInstanceId) {
        this.destProcessInstanceId = destProcessInstanceId;
    }

    public Long getDestTaskInstanceId() {
        return destTaskInstanceId;
    }

    public void setDestTaskInstanceId(Long destTaskInstanceId) {
        this.destTaskInstanceId = destTaskInstanceId;
    }
}
